package org.chen.q6;

import okhttp3.*;

import java.io.IOException;
import java.util.Scanner;

public class MyOkHttpClient {

    public static void main(String[] args) {
        String url = "http://localhost:8801";
        final OkHttpClient httpClient = new OkHttpClient.Builder().build();
        final Request request = new Request.Builder()
                .url(url)
                .get()
                .build();
        Call call =httpClient.newCall(request);
        Response response = null;
        try {
            response = call.execute();
            System.out.println("请求成功：");
            Scanner sc = new Scanner(response.body().charStream());
            while (sc.hasNext()){
                System.out.println(sc.nextLine());
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (response != null){
                response.close();
            }

        }
    }
}
